package contegor.scire.structure.queries;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import contegor.scire.core.Id;
import contegor.scire.core.Link;
import contegor.scire.core.queries.Condition;
import contegor.scire.core.queries.GetLinksFromSource;
import contegor.scire.core.queries.GetTargetsFromLinks;
import contegor.scire.core.queries.Query;

/**
 * Base for 'upstream' recursive {@link Query}s.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
public class BaseUpstreamRecursiveQuery extends GetTargetsFromLinks {
  private static final long serialVersionUID = -1246690102373169339L;

  public BaseUpstreamRecursiveQuery(Id id, Condition<Link> select, Condition<Link> accept) {
    super(id.getParentId());
    List<Query<Link>> aux = new ArrayList<Query<Link>>(1);
    aux.add(new GetLinksFromSource(id).withIt(new RecursiveQuery<Link>(id.getParentId(),
                                              new Replicator<CircularGetLinksUpstream>(CircularGetLinksUpstream.class),
                                              select,
                                              accept)));
    this.dependencies = Collections.unmodifiableList(aux);
  }
}